<style type="text/css">
.layui-form-item .layui-input-inline {
    margin-left: 110px;
    min-height: 36px;
    margin-right: 10px;
}
.task_title_class{min-height:46px;}
.layui-form-label{font-weight:600;}
.layui-form-item{margin-bottom:8px;}
</style>
<form class="layui-form" action="{:url()}" method="post" id="editForm">
<table width="100%" bordercolor="#333" border="0">
  <tr>
    <td colspan="2">
    {:FormExt::textarea('任务标题', 'name',$task['name'] , '', '请输入任务标题','layui-textarea field-content task_title_class', 'rows="2"')}
    </td>
  </tr>
  <tr>
    <td width="380">{:FormExt::select('所属项目', 'project_id',$task['project_id'], [''=>'请选择']+$projectKV, '', '', 'lay-verify="required" lay-filter="project_id"')}</td>
    <td width="60%">{:FormExt::radio('优先级', 'priority', $task['priority'],[2=>'普通',4=>'重要'], '', '')}</td>
  </tr>
  <tr>
    <td colspan="2">
    	<div class="layui-form-item">
        <table border="0" width="100%">
              <tr>
                <td width="110" align="right"><strong>执行人： &nbsp;</strong></td>
                <td width="220"><select name="execute_uid" lay-filter="execute_uid" lay-search="">
                                {foreach $projectUserList as $k => $v}
                                <option value="{$k}">{$v}</option>
                                {/foreach}
                            </select></td>
                <td align="right" width="80"><strong>协助人：</strong></td>
                <td><div id="join_admin_ids"></div></td>
              </tr>
        </table>
        </div>
    </td>
  </tr>
  <tr>
    <td width="380">{:FormExt::input('关联订单号', 'client_ordernum', $task['client_ordernum'], '输入订单号,多个/隔开', '', '')}</td>
    <td>
       {:FormExt::select('关联物料', 'order_materialid',$task['project_id'], [''=>'请选择(先左则填写订单号)'], '', '', 'lay-filter="order_materialid" onChange="setRemark(this)" class="order_materialid"')}
    </td>
  </tr>
  <tr>
    <td colspan="2">
    <div class="layui-form-item">
        <label class="layui-form-label">补充描述</label>
        <div class="layui-input-block"><textarea class="layui-textarea field-content" name="content" id="content" autocomplete="off" placeholder="补充描述">{$task['content']}</textarea>  </div>
    </div>
	</td>
  </tr>
  <tr>
    <td> </td>
    <td width="60%"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><div class="layui-inline upload" style="width:280px; padding-left:30px;padding-bottom:15px;display:none;">
            任务附件：<button type="button" name="upload" class="layui-btn layui-btn-primary layui-upload" lay-type="image" lay-data="{exts:'jpg|png|gif|bmp|jpeg', accept:'images'}">上传附件</button>
            <input type="hidden" class="upload-input" name="pic" value="{:arrayGet($formData, 'pic', '')}">
            {if condition="arrayGet($formData, 'pic', '') != ''"}
                <img src="{:arrayGet($formData, 'pic', '')}" style="display:inline-block;border-radius:5px;border:1px solid #ccc" width="36" height="36">
            {else /}
                <img src="" style="display:none;border-radius:5px;border:1px solid #ccc" width="36" height="36">
            {/if}
        </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<!--	{:FormExt::setInline(false)}
	{:FormExt::setInputInline(false)}
    {:FormExt::select('所属项目', 'project_id', '', $projectKV, '', '', 'lay-verify="required"')}
    {:FormExt::input('任务名称', 'name', '', '请输入任务名称', 'required', 'lay-verify="required"')}
	{:FormExt::input('物料SKU', 'material_sku', '', '请输入物料SKU', '', '')} 
    {:FormExt::textarea('详细内容', 'content', '', '', '详细内容')}-->
    <div class="pop-bottom-bar">
    	<input type="hidden" class="field-id" name="task_id" value="{$task['id']}">
        <input type="hidden" class="material_ids" name="material_ids" value="{$task['material_id']}">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit" hisi-data="{pop: true, refresh: true}">提交保存</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>
</form>

{include file="system@block/layui" /}
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js"></script>  
<script>
var formData = {:json_encode($formData)};
var allProUsers={:json_encode($allProUsers)};
var doubleSelects={:json_encode($doubleSelects)};
layui.use(['form', 'func'], function() {
	var $ = layui.jquery, form = layui.form;
	//layui.func.assign(formData);
	$(".layui-input-inline").addClass("layui-input-block").removeClass("layui-input-inline");
	
	var joinAdminsSelect = xmSelect.render({
		el: '#join_admin_ids', 
		name:'join_admin_ids',
		autoRow: true,
		filterable: true,
		data: {:json_encode($taskJoinUsers)}
	});
	

	form.on('select(order_materialid)', function(data){
		var selectOption=$("select option[value='"+data.value+"']").attr("data-name")+" ";
		$("#content").val( $("#content").val()=='' ? selectOption : $("#content").val()+"\r\n" + selectOption );
		var checked_mids=$(".material_ids").val();
		checked_mids=checked_mids==0? '' : checked_mids;
		
		var reg = new RegExp(data.value+"\,","g");//g,表示全部替换。
		checked_mids=checked_mids.replace(reg,"");
		$(".material_ids").val(checked_mids+data.value+",");
		$("#content").focus();
		//alert(selectOption);
	});

	// 项目下拉切换执行人
	form.on('select(project_id)', function(data){
		var optionArr = allProUsers[data.value];
		var option = '';
		for(var i in optionArr) {
			option += '<option value="'+i+'">'+optionArr[i]+'</option>';
		}
		$("select[name=execute_uid] option").remove();
		$('select[name=execute_uid]').append(option);
		joinAdminsSelect.update({
			data:doubleSelects[data.value]
		});
		form.render();
	});
	
	$(document).on('input propertychange',".field-client_ordernum", function() {
		var order_number=$(this).val();
		if(order_number==''){
			return;
		}
		if(order_number.length>=7){
			$.ajax({
				type: "post",
				url: "{:url()}"+"?action=getOrderMaterials&order_number="+order_number,
				data: {},
				dataType: "json",
				success: function (res) {
					$('.field-order_materialid').html(res.data.optionstr);
					layui.form.render();
				}
			});
		}
		
	});

});
</script>